home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 424_01 / ed_157 / insert_win.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-16  |  4.3 KB  |  138 lines

  1. /*
  2.  * Copyright (C) 1992 by Rush Record (rhr@clio.rice.edu)
  3.  * 
  4.  * This file is part of ED.
  5.  * 
  6.  * ED is free software; you can redistribute it and/or modify it under the terms
  7.  * of the GNU General Public License as published by the Free Software Foundation.
  8.  * 
  9.  * ED is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  10.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  11.  * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  12.  * 
  13.  * You should have received a copy of the GNU General Public License along with ED
  14.  * (see the file COPYING).  If not, write to the Free Software Foundation, 675
  15.  * Mass Ave, Cambridge, MA 02139, USA.
  16.  */
  17. #include "opsys.h"
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22.  
  23. #include "rec.h"
  24. #include "window.h"
  25. #include "ed_dec.h"
  26. #include "handy.h"
  27.  
  28. static Char percentaged = 0;
  29. static Int percent;
  30.  
  31. /******************************************************************************\
  32. |Routine: insert_window_percent
  33. |Callby: edit news_group
  34. |Purpose: Allows calling code to require that the created window occupy a given
  35. |         percentage of the bottommost window.
  36. |Arguments:
  37. |    perc is the percentage, 0-100, integer.
  38. \******************************************************************************/
  39. void insert_window_percent(perc)
  40. Int perc;
  41. {
  42.     percentaged = 1;
  43.     percent = perc;
  44. }
  45.  
  46. /******************************************************************************\
  47. |Routine: insert_window
  48. |Callby: command edit wincom
  49. |Purpose: Handles creation of a new window on the screen.
  50. |Arguments:
  51. |    file is the name of the file for the window.
  52. |    base is the base of the record queue for the new window.
  53. |    binary flags that the window is in binary or hex mode.
  54. |    diredit flags that the window is a diredit window.
  55. \******************************************************************************/
  56. void insert_window(file,base,binary,diredit)
  57. Char *file;
  58. rec_ptr base;
  59. Int binary,diredit;
  60. {
  61.     Int i,j,diff,rows,space,excess,trim;
  62.  
  63.     diff = WINDOW[NWINDOWS - 1].botrow - WINDOW[NWINDOWS - 1].toprow;
  64.     if(percentaged)
  65.     {
  66.         percentaged = 0;
  67.         rows = ((diff + 1) * percent) / 100;
  68.     }
  69.     else
  70.         rows = (diff + 2) >> 1;
  71.     if(rows < 4)
  72.     {
  73.         space = 6 - diff;    /* we have to get this many lines from existing windows */
  74.         for(i = 0;i < NWINDOWS - 1;i++)
  75.             if((excess = WINDOW[i].botrow - WINDOW[i].toprow - 2) > 0)    /* there is space available here, use it */
  76.             {
  77.                 trim = min(space,excess);
  78.                 marge(1,NROW);
  79.                 move(WINDOW[i].botrow - trim + 1,1);
  80.                 del_line(trim);
  81.                 WINDOW[i].botrow -= trim;
  82.                 new_botrec(i);
  83.                 calc_limits(WINDOW[i].toprow,WINDOW[i].botrow,&WINDOW[i].toplim,&WINDOW[i].botlim);
  84.                 if(WINDOW[i].currow > WINDOW[i].botlim)
  85.                 {
  86.                     set_window(i);
  87.                     CURROW -= scroll_up(CURROW - BOTLIM);
  88.                     save_window();
  89.                 }
  90.                 for(j = i + 1;j < NWINDOWS;j++)
  91.                 {
  92.                     WINDOW[j].toprow -= trim;
  93.                     WINDOW[j].botrow -= trim;
  94.                     WINDOW[j].toplim -= trim;
  95.                     WINDOW[j].botlim -= trim;
  96.                     WINDOW[j].currow -= trim;
  97.                 }
  98.                 if(!(space -= trim))
  99.                     break;
  100.             }
  101.         rows = 4;
  102.     }
  103.     i = NWINDOWS - 1;
  104.     WINDOW[i].botrow = NROW - rows;
  105.     new_botrec(i);
  106.     calc_limits(WINDOW[i].toprow,WINDOW[i].botrow,&WINDOW[i].toplim,&WINDOW[i].botlim);
  107.     if(WINDOW[i].currow > WINDOW[i].botlim)
  108.     {
  109.         set_window(i);
  110.         CURROW -= scroll_up(CURROW - BOTLIM);
  111.         save_window();
  112.     }
  113.     WINDOW[NWINDOWS].base = base;
  114.     WINDOW[NWINDOWS].currec = base->next;
  115.     WINDOW[NWINDOWS].toprec = base->next;
  116.     WINDOW[NWINDOWS].curbyt = 0;
  117.     WINDOW[NWINDOWS].toprow = WINDOW[NWINDOWS].currow = NROW - rows + 2;
  118.     WINDOW[NWINDOWS].botrow = NROW;
  119.     new_botrec(NWINDOWS);
  120.     calc_limits(WINDOW[NWINDOWS].toprow,WINDOW[NWINDOWS].botrow,&WINDOW[NWINDOWS].toplim,&WINDOW[NWINDOWS].botlim);
  121.     WINDOW[NWINDOWS].curcol = WINDOW[NWINDOWS].firstcol = WINDOW[NWINDOWS].wantcol = 1;
  122.     WINDOW[NWINDOWS].modified = 0;
  123.     WINDOW[NWINDOWS].filebuf = NULL;
  124.     WINDOW[NWINDOWS].filename = (Char *)imalloc(strlen(file) + 1);
  125.     strcpy(WINDOW[NWINDOWS].filename,file);
  126.     WINDOW[NWINDOWS].bookmark = NULL;
  127.     WINDOW[NWINDOWS].binary = binary;
  128.     WINDOW[NWINDOWS].news = 0;    /* this is the default, newsreading code must change it. */
  129. /* if this is a remote diredit buffer, store in the list for this window */
  130.     if(host_in_name(file) && diredit)
  131.         dir_store(NWINDOWS,file,base);
  132.     set_window(NWINDOWS);
  133.     move(TOPROW,1);
  134.     ers_bottom();
  135.     ref_window(NWINDOWS++);
  136. }
  137.  
  138.